package com.example.xiaomi.Model.Oop;

import java.util.ArrayList;
import java.util.List;

public class Algorithm {
    public static String split(String str, char c) {
        List<String> strList = new ArrayList<>();
        int start = 0;
        for (int i = 0; i < str.length(); ) {
            char sc = str.charAt(i);
            if (c == sc) {
                if (start < i) {
                    System.out.println("添加的元素为：" + str.substring(start, i));
                    strList.add(str.substring(start, i));
                }
                start = ++i;
            } else {
                i++;
            }
        }
        // start是根据c计数，不是以c结尾的str在这里加个判断
        if (start < str.length()) {
            System.out.println("添加的元素为：" + str.substring(start, str.length()));
            strList.add(str.substring(start, str.length()));
        }
        System.out.println(strList.toString());
        return str;
    }
}
